using System;
using System.Collections.Generic;
using System.Text;
using OhioState.Graphics.IAssetManaged;
using OhioState.Graphics.Layer;
using Tao.OpenGl;

namespace OSU_GL_Library
{
    class TransferFunc2DHandler : TextureHandler
    {
        public TransferFunc2DHandler( IAssetManaged proxyObject )
            : base(proxyObject)
        {
            TransferFunction2D transferFunc = _textureProxy as TransferFunction2D;
            transferFunc.AddChangingEventHandler(this.invalidateState);
        }

        protected override void createGLTexture()
        {
            _realTexture = new Texture2DGL(_textureProxy.Width, _textureProxy.Height, _textureProxy.TexelType);
        }
        
        protected override void updateGLTexture()
        {
            TransferFunction2D transferFunc = _textureProxy as TransferFunction2D;
            if (transferFunc != null)
            {
                int xDim;
                int yDim;
                byte[] byte_buffer;
                int format = OhioState.Graphics.TextureManager.PixelFormat[transferFunc.TexelType.Format];
                int type = OhioState.Graphics.TextureManager.PixelBuffer[transferFunc.TexelType.Type];
                byte_buffer = transferFunc.GetTextureByte(out xDim, out yDim);
                Gl.glTexSubImage2D(Gl.GL_TEXTURE_2D, 0, 0, 0, xDim, yDim, format, type, byte_buffer);
            }
        }
    }
}
